import Vue from 'vue'
import App from './App'
import router from './router'

import axios from 'axios'

Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  render: h => h(App)
})
// 1.axios基本使用
// axios 全局设置
axios.defaults.baseURL = 'http://localhost:8000'
axios.defaults.timeout = 5000
axios({
  url: '/admin/test/arraytest',
  method: 'GET'
}).then(res => {
  console.log(res)
})

// GET方式传参数 params
axios({
  url: '/admin/test/catelist',
  params: {
    // url查询get
    page: 2
  },
  method: 'GET'
}).then(res => {
  console.log(res)
})

// post方式传参数 data
axios({
  url: '/admin/test/dbtest',
  data: {
    // request body
    username: 'sc',
    password: '123456'
  },
  method: 'POST'
}).then(res => {
  console.log(res)
})

// 2.axios并发使用
// axios.all([axios(), axios()]).then(results => {})
/* axios.all([axios(), axios()]).then(
  axios.spread((res1, res2) => {
    console.log(res1)
    console.log(res2)
  })
) */

// 3.对象的解构
const obj = {
  name: 'aa',
  age: 12
}

const { name, age } = obj
console.log(name)
console.log(age)

// 4.数组解构
const names = ['aaa', 'bbb', 'ccc']
const [name1, name2, name3] = names
console.log(name1)
console.log(name2)
console.log(name3)
